package com.lixin.smartclassroom.ui.home.tab5.activity

import com.drake.net.utils.scopeDialog
import com.drake.net.utils.scopeNetLife
import com.drake.tooltip.dialog.BubbleDialog
import com.lixin.smartclassroom.api.forgotpassword
import com.lixin.smartclassroom.common.saveSuccessDialog
import com.lixin.smartclassroom.databinding.ActivityChangePwdBinding
import com.lixin.smartclassroom.databinding.ActivitySetBinding
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.text
import com.lixinkeji.extension.toast

/**
 * Description 更改密码
 * Author: lwc
 * Date:2023/12/9 11:39
 */
class ChangePwdAct : BaseActivity<ActivityChangePwdBinding>() {
    override fun getViewBinding() = ActivityChangePwdBinding.inflate(layoutInflater)

    override fun topBarHide() = false
    override fun startPadding() = true
    override fun title() = "更改密码"


    override fun iniView() {


    }

    override fun onClick() {
        binding.apply {
            btnCommit.onClick {
                if (etOldPwd.text().isEmpty()) {
                    toast("请输入旧密码")
                    return@onClick
                }
                if (etNewPwd.text().isEmpty()) {
                    toast("请输入新密码")
                    return@onClick
                }
                if (etNewPwdAgain.text().isEmpty()) {
                    toast("请再次输入新密码")
                    return@onClick
                }
                if (etNewPwd.text() != etNewPwdAgain.text()) {
                    toast("两次输入新密码不一致")
                    return@onClick
                }
                val dialog = BubbleDialog(this@ChangePwdAct)
                scopeDialog(dialog) {
                    val baseBean = forgotpassword(etOldPwd.text(), etNewPwd.text())
                    if (baseBean.result == "0") {
                        saveSuccessDialog("修改成功")
                        finish()
                    } else {
                        toast(baseBean.resultNote.toString())
                    }

                }
            }
        }
    }


}